package com.mf.all.controller.basic;


import com.mf.all.entity.req.publicReq.ReqPublicIds;
import com.mf.all.groups.GroupsAddInterface;
import com.mf.all.groups.GroupsUpdateInterface;
import com.mf.all.result.Result;
import com.mf.all.utils.UtilController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.all.entity.dto.DtoSet;
import com.mf.all.entity.req.basic.ReqSet;
import com.mf.all.service.ServiceSet;
import com.mf.all.entity.req.search.basic.SearchReqSet;

import java.util.List;

/**
 * 系统全局设置
 *
 * @date 2025-04-02 22:36:48
 */
@RestController
@RequestMapping("set")
@Tag(name = "系统全局设置")
public class ControllerSet {
    @Resource
    private ServiceSet serviceSet;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("set:search")
    public Result<Page<DtoSet>> findPage(@RequestBody SearchReqSet searchReqSet) {
        return Result.success(serviceSet.findPageByParams(searchReqSet));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    @SaCheckPermission("set:search")
    public Result<List<DtoSet>> list(@RequestBody SearchReqSet searchReqSet) {
        return Result.success(serviceSet.findListByParams(searchReqSet));
    }

    @Operation(summary = "保存")
    @PostMapping("/save")
    @SaCheckPermission("set:save")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqSet reqSet) {
        serviceSet.save(UtilController.setBo(reqSet, DtoSet.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    @SaCheckPermission("set:update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqSet reqSet) {
        serviceSet.updateById(UtilController.setBo(reqSet, DtoSet.class));
        return Result.success();
    }

    @Operation(summary = "删除")
    @PostMapping("/delete")
    @SaCheckPermission("set:delete")
    public Result<Void> delete(@Validated @RequestBody ReqPublicIds<Integer> reqPublicIds) {
        serviceSet.removeByIds(reqPublicIds.getIds());
        return Result.success();
    }

}
